package com.canic.dkd.web.shop.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.canic.dkd.web.merchandise.dto.MerchandiseOutputDTO;
import com.canic.dkd.web.shop.dto.ShopOutputDTO;
import com.canic.dkd.web.shop.entity.Shop;
import com.canic.dkd.web.shop.mapper.ShopMapper;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 * ShopServiceImpl
 * @author ZC
 */
@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper,Shop> implements ShopService {

    /**
     * 返回空值更优雅一些
     * @return
     */
    @Override
    public List<Shop> fullList() {
        List<Shop> list = baseMapper.fullList();
        if(CollectionUtils.isEmpty(list)){
            return Lists.newArrayList();
        }
        return list;
    }

    @Override
    public Page<Shop> findAllShopPage(Page<Shop> page) {
        page.setRecords(baseMapper.findAllShopPage(page));
        return page;
    }

    @Override
    public List<Shop> eligibleList(Shop shop) {
        List<Shop> list = baseMapper.eligibleList(shop);
        if(CollectionUtils.isEmpty(list)){
            return Lists.newArrayList();
        }
        return list;
    }

    @Override
    public Page<Shop> eligiblePageList(Page<Shop> page, Shop shop) {
        page.setRecords(baseMapper.eligibleList(page, shop));
        return page;
    }

    @Override
    public Page<ShopOutputDTO> eligibleComplexPageList(Page<ShopOutputDTO> page, Map<String, Object> paraMap) {
        // 只实现了一层体，体的体没有实现
        List<ShopOutputDTO> shopOutputDTOs = baseMapper.eligibleComplexPageList(page, paraMap);
        page.setRecords(shopOutputDTOs);
        return page;
    }

    @Override
    public Page<MerchandiseOutputDTO> getMerchandiseListByTypeId(Page<MerchandiseOutputDTO> page, Map<String, Object> paraMap) {
        page.setRecords(baseMapper.getMerchandiseListByTypeId(page, paraMap));
        return page;
    }
}
